<?php $this->load->view('common/admin_header');?>
<link rel="stylesheet" type="text/css" href="<?=base_url('themes/admins/js/fancybox/jquery.fancybox-1.3.4.css')?>" media="screen" />
<script type="text/javascript" src="<?=base_url('themes/admins/js/fancybox/jquery.fancybox-1.3.4.pack.js')?>"></script>
<script type="text/javascript" charset="utf-8">
    $(document).ready(function() {
        $("#thumbnail").fancybox({
            helpers:{title:{type:'float'}}
        });
    });
</script>
<div class="block">
    <div class="block_head">
        <div class="bheadl"></div>
        <div class="bheadr"></div>
        <h2><?=$lang['global_lable_36']?></h2>
        <ul>
            <li><a href="<?=site_url('admins/specs')?>"><?=$lang['global_lable_37']?></a></li>
        </ul>
    </div>
    <!-- .block_head ends -->
    <div class="block_content">
        <?php $this->load->view('common/notify');?>
        <form id="form" action="<?=site_url('admins/specs/edit');?>" method="post">
            <input type="hidden" name="id" value='<?php echo isset($row['id']) ? $row['id'] : '';?>' />

            <p>
                <label><?=$lang['content_lable_47']?>:</label>
                <input type="text" class="text small" name="name" value='<?php echo isset($row['name']) ? $row['name'] : '';?>'/>
            </p>
            <p>
                <label><?=$lang['content_lable_48']?>:</label>
                <input type="text" class="text small" name="name_en" value='<?php echo isset($row['name_en']) ? $row['name_en'] : '';?>'/>
            </p>
            <p>
                <label><?=$lang['content_lable_12']?>:</label>
                <select name="cat_id">
                    <?php if($cates):?>
                        <?php foreach($cates as $cat):?>
                            <?php if($cat->language_id==$type):?>
                                <option value="<?php echo $cat->category_id;?>"><?php echo $cat->title;?></option>
                            <?php endif;?>
                        <?php endforeach;?>
                    <?php endif;?>
                </select>
            </p>
            <!-- <p>
        <label><?=$lang['content_lable_35']?>:</label>
        <textarea type="text" class="text small " style="width:410px;" name="items" /><?php echo isset($row['items']) ? $row['items'] : '';?></textarea>
      </p> -->
            <div id="spec-items">
                <label><?=$lang['content_lable_35']?>:</label>
                <?php if(count($row['items']) > 0):?>
                    <?php foreach($row['items'] as $k=>$item):?>
                        <p>
                        <input type="text" name="items[<?=$item['id']?>]" value="<?=$item['name']?>" class="text small" style="width: 190px;" placeholder="<?=$lang['content_lable_47']?>" /> -
                        <input type="text" name="items_en[<?=$item['id']?>]" value="<?=$item['name_en']?>" class="text small" style="width: 190px;" placeholder="<?=$lang['content_lable_48']?>"/>
                        <input type="text" name="price[<?=$item['id']?>]" value="<?=$item['price']?>" class="text small" style="width: 120px;" placeholder="单价"/>
                        <?php if($k==0):?>
                            <button class="btn btn-primary addspec-item" type="button"><?=$lang['global_lable_23']?></button>
                        <?php else: ?>
                            <button class="btn btn-danger delete-item" data-href="<?=base_url('admins/specs/delSpecItem')?>?item_id=<?=$item['id']?>" data-id="<?=$item['id']?>" type="button"><?=$lang['global_lable_25']?></button>
                        <?php endif;?>

                    <?php endforeach;?>
                <?php else:?>
                    <input type="text" name="items[]" value="" class="text small" style="width: 190px;" placeholder="<?=$lang['content_lable_47']?>" /> -
                    <input type="text" name="items_en[]" value="" class="text small" style="width: 190px;" placeholder="<?=$lang['content_lable_48']?>"/>
                    <input type="text" name="price[]" value="" class="text small" style="width: 120px;" placeholder="<?=$lang['content_lable_50']?>"/>
                    <button class="btn btn-primary addspec-item" type="button"><?=$lang['global_lable_23']?></button>
                    </p>
                <?php endif;?>
            </div>
            <p>
                <label><?=$lang['content_lable_13']?>:</label>
                <select name="pos_id">
                    <?php if($posname):?>
                        <?php foreach($posname as $pos):?>
                            <?php if($getlang=='zh-tw'):?>
                                <option value="<?php echo $pos->id;?>" ><?php echo $pos->pos_title;?></option>
                            <?php else:?>
                                <option value="<?php echo $pos->id;?>" ><?php echo $pos->pos_name;?></option>
                            <?php endif;?>
                        <?php endforeach;?>
                    <?php endif;?>
                </select>
            </p>

            <p>
                <label><?=$lang['content_lable_14']?>:</label>
                <input type="radio" class="radio" name="is_pos" value="1"  <?=isset($row['is_pos']) && $row['is_pos']==1?'checked':''?> />
                <span><?=$lang['settings_lable_5']?></span>
                <input type="radio" class="radio" name="is_pos" value="2" <?=isset($row['is_pos']) && $row['is_pos']==2?'checked':''?> />
                <span><?=$lang['settings_lable_6']?></span>
            </p>
            <p>
                <label><?=$lang['global_lable_17']?>:</label>
                <input type="text" class="text small" name="sort" value='<?php echo isset($row['sort']) ? $row['sort'] : '';?>'/>
            </p>
            <p>
                <label><?=$lang['global_lable_16']?>:</label>
                <input type="radio" class="radio" name="status" value="1"  <?=isset($row['status']) && $row['status']==1?'checked':''?> />
                <span><?=$lang['global_lable_37']?></span>
                <input type="radio" class="radio" name="status" value="0" <?=isset($row['status']) && $row['status']==0?'checked':''?> />
                <span><?=$lang['global_lable_38']?></span>
            </p>
            <p>
                <label><?='配料'?>:</label>
                <input type="radio" class="radio" name="is_trans" value="1"  <?=isset($row['is_trans']) && $row['is_trans']==1?'checked':''?> />
                <span><?=$lang['settings_lable_5']?></span>
                <input type="radio" class="radio" name="is_trans" value="0" <?=isset($row['is_trans']) && $row['is_trans']==0?'checked':''?> />
                <span><?=$lang['settings_lable_6']?></span>
            </p>
            <p>
                <input class="btn btn-primary" type="submit" name="btn_save" value="<?=$lang['global_lable_12']?>" />
                <input class="btn" type="reset" value="<?=$lang['global_lable_13']?>"/>
            </p>
        </form>
    </div>
    <!-- .block_content ends -->
    <div class="bendl"></div>
    <div class="bendr"></div>
</div>
<!-- .block ends -->
<script type="text/javascript" id="for-spec-items">
    <p >
    <input type="text" name="items[]" value="" class="text small" style="width: 190px;" placeholder="<?=$lang['content_lable_47']?>" /> -
        <input type="text" name="items_en[]" value="" class="text small" style="width: 190px;" placeholder="<?=$lang['content_lable_48']?>"/>
        <input type="text" name="price[]" value="" class="text small" style="width: 120px;" placeholder="<?=$lang['content_lable_50']?>"/>
        <button class="btn btn-danger delete-item" data-href="" data-id="0" type="button"><?=$lang['global_lable_25']?></button>
        </p>
</script>
<script type="text/javascript" charset="utf-8">
    $("body").on('click',".addspec-item",function(){
        var _itemHtml = $("#for-spec-items").html();
        $("#spec-items").append(_itemHtml);
    })
    $("body").on('click',".delete-item",function(){
        var _this = $(this);
        if(_this.hasClass("disabled")){return false;}

        if(_this.data('id')*1 > 0){
            if(!confirm('确定删除该项吗?')){
                return false;
            }
            $.post(_this.data('href'),{},function(result){
                if(result.status == 1){
                    _this.parent().remove();
                }else{
                    alert(result.info)
                }
            },"json")
        }else{
            _this.parent().remove();
        }
    })
</script>
<?php $this->load->view('common/admin_footer');?>

